/**
 * @Author:       lee
 * @DateTime:     2017-11-06 00:57:46
 * @Description:  symbol
 */
/**
 *  创建Symbol
 *  Symbol()函数接收一个参数，用于描述即将创建的Symbol
 *  支持typeof检测
 */
let firstName = Symbol('this is the first name');
let person = {}
// person.firstName = 'funlee';
person[firstName] = 'funlee';
console.log(person.firstName)//funlee
console.log(firstName)//Symbol(this is the first name)
console.log(typeof firstName)
/**
 *  Symbol共享体系
 *  Symbol.for(),只接受一个参数，-----字符串标示符
 *  
 */
let uid = Symbol.for('uid');
let object = {
  [uid]:'123456'
}
console.log(object[uid])
console.log(uid)

let uid2 = Symbol.for('uid')

console.log(uid === uid2)
console.log(object[uid2])
console.log(uid2)
/**
 *  Symbol.keyFor()在Symbol全局注册表中检索与Symbol有关的键
 */
let uid = Symbol.for('uid');
console.log(Symbol.keyFor(uid))//uid

let uid2 = Symbol.for('uid');
console.log(Symbol.keyFor(uid2))//uid

let uid3 = Symbol('uid');
console.log(Symbol.keyFor(uid3))//undefined
/**
 *  Symbol 类型转换
 */
let funlee2 = Symbol.for('uid');
let desc = String(funlee2);
console.log(desc)
console.log(String(funlee2))

let funle = Symbol.for('test');
console.log(String(funlee))//这样为什么不行---------？？？？？？？？？？？？？？？？？？？？？？？？？？---------
/**
 *  Symbol属性检索
 */
let attr1 = Symbol.for('uid1');
let attr2 = Symbol.for('uid2');

let object = {
  [attr1]:'test1',//使用可计算对象字面量属性
  [attr2]:'test2'//使用可计算对象字面量属性
}

let symbols = Object.getOwnPropertySymbols(object)
console.log(symbols.length)//2
console.log(symbols[0])
console.log(object[symbols[0]])//test1
console.log(object[symbols[1]])//test2
/**
 *  well-known Symbol
 */